package org.summerframework.component.security.spring.config;

import org.summerframework.component.security.core.service.LoginManage;
import org.summerframework.component.security.spring.SecurityRoleService;
import org.summerframework.component.security.spring.filter.LoginFilter;
import org.springframework.security.config.annotation.web.HttpSecurityBuilder;
import org.springframework.security.config.annotation.web.configurers.AbstractAuthenticationFilterConfigurer;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
import org.springframework.security.web.util.matcher.RequestMatcher;

/**
 * @author 石超
 * @version v1.0.0
 */
public class LoginConfigurer<H extends HttpSecurityBuilder<H>> extends
        AbstractAuthenticationFilterConfigurer<H, LoginConfigurer<H>, LoginFilter> {
    public LoginConfigurer() {
        super(new LoginFilter(), null);
    }

    @Override
    public RequestMatcher createLoginProcessingUrlMatcher(String loginProcessingUrl) {
        super.loginPage(loginProcessingUrl);
        return new AntPathRequestMatcher(loginProcessingUrl);
    }

    public LoginConfigurer<H> loginManager(LoginManage loginManage) {
        this.getAuthenticationFilter().setLoginManage(loginManage);
        return this;
    }

    public LoginConfigurer<H> securityRoleService(SecurityRoleService securityRoleService) {
        this.getAuthenticationFilter().setSecurityRoleService(securityRoleService);
        return this;
    }

    @Override
    public void configure(H http) throws Exception {
        super.configure(http);
    }
}
